using FreeSql.DataAnnotations;

namespace SumerCoreDevOps.Domain.Entities;

/// <summary>
/// 执行节点状态
/// </summary>
[Table(Name = "node_status")]
[Index("idx_node_key", nameof(NodeKey), true)]
public class NodeStatus
{
    [Column(IsPrimary = true, IsIdentity = true)]
    public long Id { get; set; }

    /// <summary>
    /// 节点唯一标识
    /// </summary>
    [Column(StringLength = 100)]
    public string NodeKey { get; set; } = null!;

    /// <summary>
    /// 节点名称
    /// </summary>
    [Column(StringLength = 200)]
    public string NodeName { get; set; } = null!;

    /// <summary>
    /// 连接令牌（Connection Token）
    /// 持久化令牌，用于节点重连认证，无时效性限制
    /// </summary>
    [Column(StringLength = 100)]
    public string? ConnectionToken { get; set; }

    /// <summary>
    /// 是否在线
    /// </summary>
    public bool IsOnline { get; set; }

    /// <summary>
    /// 支持的环境（JSON格式）
    /// </summary>
    [Column(StringLength = -1)]
    public string SupportedEnvironments { get; set; } = "[]";

    /// <summary>
    /// 硬件信息（JSON格式）
    /// </summary>
    [Column(StringLength = -1)]
    public string HardwareInfo { get; set; } = "{}";

    /// <summary>
    /// 当前负载数据（JSON格式）
    /// </summary>
    [Column(StringLength = -1)]
    public string? LoadData { get; set; }

    /// <summary>
    /// 最后心跳时间
    /// </summary>
    public DateTime? LastHeartbeatTime { get; set; }

    /// <summary>
    /// 注册时间
    /// </summary>
    public DateTime RegisteredAt { get; set; } = DateTime.UtcNow;

    /// <summary>
    /// 任务列表
    /// </summary>
    [Navigate(nameof(TaskEntity.NodeId))]
    public List<TaskEntity> Tasks { get; set; } = [];
}
